<!--  -->
<template>
  <div class="">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品分类</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-button type="primary" @click="addGoods()">添加分类</el-button>
      <table-tree
        :data="goodsList"
        :columns="columns"
        border
        :selection-type="false"
        :expand-type="false"
        :show-index="true"
        index-text="#"
      >
        <template slot="isdelete" slot-scope="scope">
          <i
            class="el-icon-success"
            v-if="scope.row.isdelete == false"
            style="color: lightgreen"
          ></i>
          <i class="el-icon-error" v-else style="color: red"></i>
        </template>
        <template slot="type" slot-scope="scope">
          <el-tag type="success" v-if="scope.row.type == 1">一级</el-tag>
          <el-tag v-else-if="scope.row.type == 2">二级</el-tag>
          <el-tag type="warning" v-else>三级</el-tag>
        </template>
        <template slot="operate">
          <el-button type="success" icon="el-icon-edit" size="mini"
            >编辑</el-button
          >
          <el-button type="warning" icon="el-icon-delete" size="mini"
            >删除</el-button
          >
        </template>
      </table-tree>
      <el-pagination
        :page-size="100"
        layout="total, prev, pager, next"
        :total="1000"
      >
      </el-pagination>
    </el-card>

    <el-dialog
      title="添加分类"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <el-form :model="Goods_cate" :rules="Goods_cateRules" ref="Goods_cateRef" label-width="100px">
         <el-form-item label="分类名称" prop="goodsname" >
           <el-input v-model="Goods_cate.goodsname" ></el-input>
         </el-form-item>
         <el-form-item label="父级分类">
              <el-cascader

    :props="{ expandTrigger: 'hover' }"
 ></el-cascader>
         </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：
import tableTree from "vue-table-with-tree-grid";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    tableTree,
  },
  data() {
    //这里存放数据
    return {
      goodsList: [],
      columns: [
        {
          label: "分类名称",
          prop: "goodsname",
        },
        {
          label: "是否有效",
          type: "template",
          template: "isdelete",
        },
        {
          label: "级别",
          type: "template",
          template: "type",
        },
        {
          label: "操作",
          type: "template",
          template: "operate",
        },
      ],
      dialogVisible:false,
      Goods_cateRules:{
          goodsname:[
              {required:true,message:"请输入分类名称",trigger:'blur'}
          ]
      },
      Goods_cate:{
          goodsname:''
      }
    }

  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    async requestGoods() {
      let { data: res } = await this.$http.get("/goods");
      console.log(res);
      if (res.err == 0) {
        this.$message.success("数据请求成功");
        this.goodsList = res.data;
      } else {
        this.$message.error("数据请求失败");
      }
    },
    addGoods() {
        this.dialogVisible = true
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.requestGoods();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  deactivated() {},
};
</script>
<style  scoped>
.el-breadcrumb {
  margin-bottom: 10px;
}
.zk-table {
  margin: 15px;
}
</style>